import request from '@/utils/request'
import { encrypt,decrypt } from '@/api/aesUtil.js'

export function querySignature(param) {

  let signature = encrypt('{"modelType":"'+param+'","time":'+'"'+getCurrentTime()+'"}')
  return request({
    url: '/wxcomm/querySignature?modelType='+param,
    method: 'post',
    data: {"signature":signature}
  })
}
export function getSignature(param) {

  let signature = decrypt(param)
  return signature
}
function getCurrentTime() {
  var date = new Date();//当前时间
  var year = date.getFullYear() //返回指定日期的年份
  var month = repair(date.getMonth() + 1);//月
  var day = repair(date.getDate());//日
  var hour = repair(date.getHours());//时
  var minute = repair(date.getMinutes());//分
  var second = repair(date.getSeconds());//秒
  
  //当前时间 
  var curTime = year + "-" + month + "-" + day
          + " " + hour + ":" + minute + ":" + second;
  return curTime;
}

function repair(i){
  if (i >= 0 && i <= 9) {
      return "0" + i;
  } else {
      return i;
  }
}
export function uploadOSSFile(ossurl,param) {
  return request({
    url: ossurl,
    method: 'post',
    data: param
  })
}